!ifndef OUTPUT_INCLUDED
!include "LogicLib.nsh"
Var /GLOBAL _stdHandle
!macro _INIT_CONSOLE
  ${If} $_stdHandle = 0
    System::Call 'kernel32::GetStdHandle(i -11)i.r0' 
    System::Call 'kernel32::AttachConsole(i -1)i.r1' 
    ${If} $0 = 0
    ${OrIf} $1 = 0
        System::Call 'kernel32::AllocConsole()'
        System::Call 'kernel32::GetStdHandle(i -11)i.r0' 
    ${EndIf}
    StrCpy $_stdHandle $0
  ${EndIf}

!macroend
!define INIT_CONSOLE "!insertmacro _INIT_CONSOLE"

!macro _WRITE_LINE_CONSOLE STR 
  ; ${INIT_CONSOLE}
  FileWrite $_stdHandle  "${STR} $\n" 
  System::Call 'FlushFileBuffers::GetStdHandle(i $_stdHandle)i.r0' 
!macroend
!define WRITE_LINE_CONSOLE "!insertmacro _WRITE_LINE_CONSOLE"

!macro _WRITE_CONSOLE STR 
  ; ${INIT_CONSOLE}
  FileWrite $_stdHandle  "${STR}" 
!macroend
!define WRITE_CONSOLE "!insertmacro _WRITE_CONSOLE"

!macro _Flush_CONSOLE
  ; ${INIT_CONSOLE}
  FileWrite $_stdHandle  "${STR}" 
!macroend
!define Flush_CONSOLE "!insertmacro _Flush_CONSOLE"

!endif